/*
 * VHMainController.java
 * Created on 28 mai 2009
 *
 * VirtualHockey Internet Platform
 * http://code.google.com/p/virtualhockey/
 *
 * Copyright (c) 2005-2009, Jens and Jan Janke (VirtualHockey Project)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses/.
 */

package com.hockeo.vhweb.client;

import java.util.List;

import com.extjs.gxt.ui.client.util.IconHelper;
import com.extjs.gxt.ui.client.widget.BoxComponent;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.hockeo.vhweb.client.mvc.VHController;
import com.hockeo.vhweb.client.rpc.VHBaseDataService;
import com.hockeo.vhweb.client.rpc.VHRpcCallback;
import com.hockeo.vhweb.client.ui.panels.VHTabPanelRRCupRound;
import com.hockeo.vhweb.client.ui.panels.VHTabPanelCup;
import com.hockeo.vhweb.client.ui.panels.VHTabPanelIntCup;
import com.hockeo.vhweb.client.ui.panels.VHTabPanelLeague;
import com.hockeo.vhweb.client.ui.widget.VHAssociationSelector;
import com.hockeo.vhweb.client.ui.widget.VHClubHistoryGrid;
import com.hockeo.vhweb.client.ui.widget.VHClubList;
import com.hockeo.vhweb.client.ui.widget.VHENRStandingsGrid;
import com.hockeo.vhweb.client.ui.widget.VHKOMatchGrid;
import com.hockeo.vhweb.client.ui.widget.VHMatchdaySelector;
import com.hockeo.vhweb.client.ui.widget.VHRRMatchGrid;
import com.hockeo.vhweb.client.ui.widget.VHRoundSelector;
import com.hockeo.vhweb.client.ui.widget.VHSeasonSelector;
import com.hockeo.vhweb.client.ui.widget.VHStandingsGrid;
import com.hockeo.vhweb.client.ui.widget.VHWinnerListGrid;
import com.hockeo.vhweb.client.utils.VHJsData;
import com.hockeo.vhweb.client.utils.enums.VHJsStandingsType;

/**
 * Main controller responsible for managing the main layout.
 *
 * @version $Id$
 * @author jjanke
 */
public class VHMainController extends VHController
{
  static final String RPC_PURPOSE_LOAD_COUNTRIES = "loadCountries";

  /**
   * Creates the main controller for VH.
   */
  protected VHMainController()
  {
    super( new VHMainView() );
  }

  /**
   * Displays the league panel in the main part of the web application.
   *
   * @param league the league for which to show the window
   */
  public void displayLeague( VHJsData league )
  {
    displayPanel( new VHTabPanelLeague( this, league ), league.getString( "id_translated" ), VHMain.ICON_LEAGUE );
  }

  /**
   * Displays the cup panel in the main part of the web application
   *
   * @param strCupId the ID of the cup contest
   * @param strCupLabel the cup's label
   */
  public void displayCup( String strCupId, String strCupLabel )
  {
    displayPanel( new VHTabPanelCup( this, strCupId ), strCupLabel, VHMain.ICON_NATIONAL_CUP );
  }

  /**
   * Displays the international cup panel in the main part of the web application
   *
   * @param intcup the international cup to be displayed
   */
  public void displayIntCup( VHJsData intcup )
  {
    displayPanel( new VHTabPanelIntCup( this, intcup ), intcup.getString( "id_translated" ), IconHelper.create(
        "images/nav/" + intcup.getId() + "_16.png", 16, 16 ) );
  }

  /**
   * Displays the given panel in the main part of the web application.
   *
   * @param panel the panel to be displayed in the application's main part
   */
  public void displayPanel( BoxComponent panel, String strTitle, AbstractImagePrototype icon )
  {
    ( (VHMainView) getView() ).setMainContent( panel, strTitle, icon );
  }

  /**
   * @see VHBaseDataService#getClubContestHistoryRecords(String, String, Integer)
   */
  public void loadClubContestHistoryRecords( VHClubHistoryGrid clubHistoryGrid, String strContestId, Integer nSeasonId )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( clubHistoryGrid, null );

    getBaseDataService().getClubContestHistoryRecords( getLocale(), strContestId, nSeasonId, callback );
  }

  /**
   * @see VHBaseDataService#getCountries(String)
   */
  public void loadAssociations( VHAssociationSelector assocSelector )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( assocSelector, null );

    getBaseDataService().getCountries( getLocale(),callback );
  }

  /**
   * @see VHBaseDataService#getStandings(String, String, VHJsStandingsType, Integer)
   */
  public void loadStandings( VHStandingsGrid standingsGrid, String strElementId, VHJsStandingsType standingsType,
      Integer nMatchday )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( standingsGrid, null );

    getBaseDataService().getStandings( getLocale(), strElementId, standingsType, nMatchday, callback );
  }

  /**
   * @see VHBaseDataService#getENRStandings(String, Integer)
   */
  public void loadENRStandings( VHENRStandingsGrid standingsGrid, Integer nSeasonId )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( standingsGrid, null );

    getBaseDataService().getENRStandings( getLocale(), nSeasonId, callback );
  }

  /**
   * @see VHBaseDataService#getKOMatches(String, String, String)
   */
  public void loadKOMatches( VHKOMatchGrid komatchGrid, String strContestId, String strRoundId )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( komatchGrid, null );

    getBaseDataService().getKOMatches( getLocale(), strContestId, strRoundId, callback );
  }

  /**
   * @see VHBaseDataService#getMatchdays(String, String)
   */
  public void loadMatchdays( VHMatchdaySelector matchdaySelector, String strElementId )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( matchdaySelector, null );

    getBaseDataService().getMatchdays( getLocale(), strElementId, callback );
  }

  /**
   * @see VHBaseDataService#getMatches(String, String, Integer)
   */
  public void loadMatches( VHRRMatchGrid matchGrid, String strElementId, Integer nMatchday )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( matchGrid, null );

    getBaseDataService().getMatches( getLocale(), strElementId, nMatchday, callback );
  }

  /**
   * @see VHBaseDataService#getMatches(String, String)
   */
  public void loadAllMatches( VHRRMatchGrid matchGrid, String strElementId )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( matchGrid, null );

    getBaseDataService().getMatches( getLocale(), strElementId, callback );
  }

  /**
   * @see VHBaseDataService#getClubsForLeague(String, String)
   */
  public void loadClubsForLeague( VHClubList clubList, String strLeagueId )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( clubList, null );

    getBaseDataService().getClubsForLeague( getLocale(), strLeagueId, callback );
  }

  /**
   * @see VHBaseDataService#getClubContestHistoryRecords(String, String, Integer)
   */
  public void loadClubsForIntCup( VHClubList clubList, String strIntCupId, Integer nSeason )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( clubList, null );

    getBaseDataService().getClubContestHistoryRecords( getLocale(), strIntCupId, nSeason, callback );
  }

  /**
   * @see VHBaseDataService#loadContestHistoryRecords(String, String)
   */
  public void loadContestHistoryRecords( VHWinnerListGrid winnerList, String strContestId )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( winnerList, null );

    getBaseDataService().getContestHistoryRecords( getLocale(), strContestId, callback );
  }

  /**
   * @see VHBaseDataService#getContestRounds(String, String)
   */
  public void loadContestRounds( VHRoundSelector roundSelector, String strContestId )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( roundSelector, null );

    getBaseDataService().getContestRounds( getLocale(), strContestId, callback );
  }

  /**
   * @see VHBaseDataService#getSeasonsForClubHistory(String, String)
   */
  public void loadSeasonsForClubHistory( VHSeasonSelector seasonSelector, String strContestId )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( seasonSelector, null );

    getBaseDataService().getSeasonsForClubHistory( getLocale(), strContestId, callback );
  }

  /**
   * @see VHBaseDataService#getSeasonsForIntRankings(String)
   */
  public void loadSeasonsForIntRanking( VHSeasonSelector seasonSelector )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( seasonSelector, null );

    getBaseDataService().getSeasonsForIntRankings( getLocale(), callback );
  }

  /**
   * @see VHBaseDataService#getHistoricStandings(String, String, Integer,
   *      VHJsStandingsType)
   */
  public void loadHistoricStandings( VHStandingsGrid standingsGrid, String strElementId, Integer nSeasonId,
      VHJsStandingsType standingsType )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( standingsGrid, null );

    getBaseDataService().getHistoricStandings( getLocale(), strElementId, nSeasonId, standingsType, callback );
  }

  /**
   * @see VHBaseDataService#getContestElements(String, String)
   */
  public void loadContestElements( VHTabPanelRRCupRound panelRRCupRound, String strRoundId )
  {
    AsyncCallback<List<VHJsData>> callback = new VHRpcCallback<List<VHJsData>>( panelRRCupRound, null );

    getBaseDataService().getContestElements( getLocale(), strRoundId, callback );
  }
}
